<?php
class Module extends ModelBase
{
	private $tableName = 'myadmin_module';
	
	public static function getInstance()
	{
		return parent::instance(__CLASS__);
	}
	
	public function getModuleInfo($mid)
	{
		$user = Yii::app()->db->createCommand()
		->select('*')
		->from($this->tableName)
		->where('module_id=:module_id', array(':module_id'=>$mid))
		->queryRow();
		return $user;
	}
	
	public function getModuleList()
	{
		$module = Yii::app()->db->createCommand()
		->select('a.*,b.app_name')
		->from($this->tableName.' a')
		->leftJoin('myadmin_app b', 'b.app_id = a.app_id')
		->where('online = 1')
		->order("module_sort asc")
		->queryAll();
		return $module;
	}
	
	public function getAllModule()
	{
		$module = Yii::app()->db->createCommand()
			->select('a.*,b.app_name')
			->from($this->tableName.' a')
			->leftJoin('myadmin_app b', 'b.app_id = a.app_id')
		/*	->where('online = 1')*/
			->order("module_sort asc")
			->queryAll();
		return $module;
	}
	
	public function insertModule($data)
	{
		$ret = Yii::app()->db->createCommand()->insert($this->tableName,$data);
		return $ret; 
	}
	
	public function updateModule($data,$mid)
	{
		if(!$mid)
		{
			return false;
		}
		$ret = Yii::app()->db->createCommand()->update($this->tableName,$data,'module_id ='.$mid);
		return $ret;
	}
	
	public function delModule($mid)
	{
		if(!$mid)
		{
			return false;
		}
		$ret = Yii::app()->db->createCommand()->delete($this->tableName,'module_id = '.$mid);
		return $ret;
	}
}